/*
 * @Author: xushuhao
 * @Email: xshmouse@163.com
 * @Date: 2020-04-22 16:56:23
 * @Last Modified by: xushuhao
 * @Last Modified time: 2020-06-12 16:28:44
 * @Description: 网络请教对象类，相当于BAL
 * ///请求示例
  // Future<Response> register({ @required String code, String city,}) {
  //   return _dio.post(
  //     '/user/email/register',
  //     queryParameters: {
  //       "code": code,
  //       "city": city,
  //     }
  //   );
  // }

  //调用示例 
  //import 'package:flutter_code_framework/utils/global.dart';
  //var rs = await G.req.user.register(code:'',city:'');
 */

import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_code_framework/utils/global.dart';

/// 用户管理相关
class ReqUser {
  final Dio _dio;

  ReqUser(this._dio);

  Future<Response> login({@required String code, @required String password}) {
    var rs= _dio.post('/User/Login', queryParameters: {
      "code": code,
      "password": password,
    }); 
    rs.then((value) =>_login(value.data));
    return rs;
  }
 _login(dynamic data){
   if(data!=null){
      G.user.init(data);
   }
 }

  //修改密码
  Future<Response> rePassword(
      {@required String oldPassword, @required String newPassword}) async{
    return _dio.post('/user/repassword', queryParameters: {
      "oldPassword": oldPassword,
      "newPassword": newPassword,
    });
  }

  //更新头像
  Future<Response> updateHeadImage({@required String key}) async{
    return _dio.post('/user/updateUserImage', queryParameters: {
      "imageKey": key,
    });
  }
}
